<template>
	<view>
		<!-- <view class="bg_red W_100vw PTB_2 flex_row_between">
			<image @click="goBack" class="WH_6vw" src="../../static/goback2.png" mode=""></image>
			<view class="font_weight_bold fontS_16 color_fff">
				{{biDet.currency_name}}
			</view>
			<view class="WH_2vw">
				
			</view>
		</view> -->
		<!-- <uni-nav-bar @clickLeft='goBack' backgroundColor='red' :statusBar='true' color="#ffffff" left-icon="back" :title="biDet.currency_name"></uni-nav-bar> -->
		<view class="P_2 ">
			<!-- <view class="B_radius_5 P_2 bg_fff font_weight_bold flex_rowL">
				<view class="MR_4 PB_1" :class="idx==0?'line_red':''" @click="tabChnage(0)">
					充值
				</view>
				<view class="MR_4 PB_1" :class="idx==1?'line_red':''" @click="tabChnage(1)">
					提现
				</view>
				<view class="MR_4 PB_1" :class="idx==2?'line_red':''" @click="tabChnage(2)">
					账单
				</view>
			</view> -->
			
			<view class="MT_2" v-if="idx==2">
				<view class="B_radius_5 P_2 bg_fff flex_row_between MB_2" v-for="(item,i) in aList" :key='i'>
					<view class="">
						<view class="color_gray PB_1 fontS_12">
							{{item.change_time}}
						</view>
						<view class="font_weight_bold fontS_16">
							{{biDet.currency_name}}
						</view>
					</view>
					<view class="flex_col_evenly">
						<view class=" PB_1">
							{{item.desc}}
						</view>
						<view class="font_weight_bold fontS_16">
							{{item.change_money}}
						</view>
					</view>
				</view>
				<view class="flex_rowC PTB_3">
					{{showText}}
				</view>
			</view>
			
			<view class="" v-if="idx==1">
				<!-- <view class="B_radius_5 P_2 flex_rowC">
					<view class="MR_4 PB_1" :key='i' v-for="(item,i) in lianList" :class="idx1==i?'line_red':''" @click="lianChange(i,item)">
						{{item}}
					</view>	
				</view> -->
				<view class="flex_row_between bg_fff P_2 B_radius_5 MT_2" @click="uOpenWin('./bilist?id='+biDet.currency_id+'&moneyId='+biDet.id)">
					<view class="">
						请选择提币地址
					</view>
					<view class="" v-if="tAds">
						{{tAds}}
					</view>
					<image v-else class="WH_4vw" src="../../static/goyou.png" mode=""></image>
				</view>
				<view class="flex_row_between bg_fff P_2 B_radius_5 MT_2">
					<view class="">
						请选输入数量
					</view>
					<input class="fontS_14 textR" type="number" v-model="tNum" placeholder="数量"/>
				</view>
				<!-- <view class="color_gray fontS_12 PTB_2">
					最多可用
				</view> -->
				<!-- <view class="flex_row_between bg_fff P_2 B_radius_5 MT_2">
					<view class="">
						网络费
					</view>
					10
				</view> -->
				<view @click="withdraw" class="color_fff font_weight_bold bg_red B_radius_5 flex_rowC PTB_2 MT_3">
					提现
				</view>
				<view class="font_weight_bold flex_rowL PTB_2">
					提现记录
				</view>
				<view class="B_radius_5 P_2 bg_fff flex_row_between MB_2" v-for="(item,i) in cList" :key='i'>
					<view class="">
						<view class="color_gray PB_1 fontS_12">
							{{item.created_at}}
						</view>
						<view class="font_weight_bold fontS_16">
							{{item.currency_name}}
						</view>
					</view>
					<view class="flex_col_evenly">
						<view class=" PB_1" :class="(item.status==1 || item.status==2)?'color_green':((item.status==-1 || item.status==3)?'color_red':'color_gray')">
							{{item.status_text}}
						</view>
						<view class="font_weight_bold fontS_16">
							{{item.transfer_money}}
						</view>
					</view>
				</view>
				
				<view class="flex_rowC PTB_3">
					{{showText}}
				</view>
			</view>
			
			<view class="" v-if="idx==0">
				<view class="B_radius_5 P_2 flex_rowC">
					<view class="MR_4 PB_1" :key='i' v-for="(item,i) in lianList" :class="idx1==i?'line_red':''" @click="lianChange(i,item)">
						{{item}}
					</view>	
				</view>
				
				
					<view class="qrimg flex_rowC" >
						<tki-qrcode
						ref="qrcode"
						:cid="String(idx1)"
						:val="codeInfo"
						:size="130"
						:unit="String(130)"
						:onval="true"
						 
						 />
					</view>
					
					<view class="PT_3 flex_rowC">
						充值地址
					</view>
					<view class="PB_3 flex_rowC">
						{{codeInfo}}
					</view>
					
					<view class="flex_rowC" v-if="codeInfo">
						<view class="PTB_2 PLR_6 pub_bg B_radius_5 color_fff" @click="copyCode">
							复制地址
						</view>
					</view>
					
					
		
				
				
				<view class="color_gray flex_rowL W_96vw fontS_10">
					温馨提示
				</view>
				
				<view class="color_gray flex_rowL W_96vw fontS_10 PTB_1">
					1.USDT钱包地址禁止充值除USDT之外的其他资产，任何非USDT资产充值将不可找回。
				</view>
				<view class="color_gray flex_rowL W_96vw fontS_10 PB_3">
					2.请务必确认设备及浏览器安全，防止信息被篡改或泄露。
				</view>
				
				<view class="font_weight_bold flex_rowL PB_2">
					充币记录
				</view>
				<view class="B_radius_5 P_2 bg_fff flex_row_between MB_2" v-for="(item,i) in tList" :key='i'>
					<view class="">
						<view class="color_gray PB_1 fontS_12">
							{{item.created_at}}
						</view>
						<view class="font_weight_bold fontS_16">
							{{biDet.currency_name}}
						</view>
					</view>
					<view class="flex_col_evenly">
						<view class=" PB_1" :class="item.pay_status==1?'color_green':(item.pay_status==2?'color_red':'')">
							{{item.pay_status_text}}
						</view>
						<view class="font_weight_bold fontS_16">
							{{item.account}}
						</view>
					</view>
				</view>
				
				<view class="flex_rowC PTB_3">
					{{showText}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import tkiQrcode from "@/components/tki-qrcode/tki-qrcode.vue"
	export default {
		components: {tkiQrcode},
		data() {
			return {
				idx:0,
				idx1:0,
				id:'',
				biDet:{},
				lian:'',
				lianList:[],
				adsDet:'',
				codeInfo:'',
				adsId:'',
				adsInfo:{},
				tAds:'',
				tNum:'',
				tList:[],
				cList:[],
				aList:[],
				page:1,
				showText:'',
				state:true,
				currencyId:'',
			}
		},
		onReachBottom() {
			if (this.state) {
				this.showTxt = '加载中...';
				this.page++
				this.getTList();
			}
		
		},
		onLoad(options) {
			console.log(options.id)
			this.id = options.id;
			this.currencyId = options.curreyid;
			this.getAds()
			// this.getBi();
			this.getTList()
			// if(options.way=='getAds'){
			// 	this.tabChnage(1);	
			// 	this.getCList();
			// }else{
				
			// }
			// if(options.adsId){
			// 	this.adsId = options.adsId;
			// 	console.log(this.adsId)
			// 	this.getAdsDet();
			// }else{
			// 	this.tAds = '';
			// }
		},
		methods: {
			getAList(){
				let _this = this;
				this.$req('account/accountLog',{currency_id:_this.currencyId,page:_this.page},function(res){
					if(res.code==1){
						if(res.data.list.length>0){
							if(res.data.page==1){
								_this.aList = res.data.list
							}else{
								_this.aList = _this.aList.concat(res.data.list)
							}
						}else{
							_this.showText = '没有更多了';
							_this.state = false;
						} 
						
						
					}
				})
			},
			getCList(){
				let _this = this;
				this.$req('withdrawals/index',{currency_id:'5',page:_this.page},function(res){
					if(res.code==1){
						if(res.data.list.length>0){
							if(res.data.page==1){
								_this.cList = res.data.list
							}else{
								_this.cList = _this.cList.concat(res.data.list)
							}
						}else{
							_this.showText = '没有更多了';
							_this.state = false;
						}
						
						
					}
				})
			},
			getTList(){
				let _this = this;
				this.$req('recharge/index',{currency_id:'5',page:_this.page},function(res){
					if(res.code==1){
						if(res.data.list.length>0){
							if(res.data.page==1){
								_this.tList = res.data.list
							}else{
								_this.tList = _this.tList.concat(res.data.list)
							}
						}else{
							_this.showText = '没有更多了';
							_this.state = false;
						}
						
						
					}
				})
			},
			withdraw(){
				let _this = this;
				if(!this.adsInfo.id){
					this.toast('请先选择提现地址')
				}else if(!this.tNum){
					this.toast('请输入提现金额')
				}else{
					this.$req('withdrawals/add',{taddress_id:_this.adsInfo.id,money:_this.tNum},function(res){
						if(res.code==1){
							//alert('aaa')
							uni.showToast({
								title:res.msg
							})
							//_this.toast()
							setTimeout(function(){
								_this.getCList()
							},500)
							
						}else{
							_this.toast(res.msg)
						}
					})
				}
				
			},
			getAdsDet(){
				let _this = this;
				this.$req('taddress/show',{id:_this.adsId},function(res){
					if(res.code==1){
						_this.adsInfo = res.data;
						_this.tAds = res.data.nickname;
					}else{
						_this.toast(res.msg)
					}
				})
			},
			copyCode(){
				let _this = this;
				uni.setClipboardData({
				    data: _this.codeInfo,
				    success: function () {
				        _this.toast('复制成功')
				    }
				});
			},
			getAds(){
				let _this = this;
				this.$req('caddress/index',{currency_id:'5',chain:'TRC20'},function(res){
					if(res.code==1){
						if(res.data.list.length){
							_this.adsDet = res.data.list[0];
							_this.codeInfo = _this.adsDet.address;
							console.log(_this.codeInfo)
							setTimeout(()=>{
								if(_this.idx==0){
									_this.$refs.qrcode._makeCode();
								}
							},1000)
							
						}else{
							
							_this.adsDet = [];
							_this.codeInfo = ''
							_this.$refs.qrcode._clearCode();
						}
						
						
						
					}else{
						_this.toast(res.msg)
					}
				})
			},
			tabChnage(i){
				this.idx=i;	
				if(i==0){
					this.getAds()
				}else if(i==1){
					this.getCList()
				}else if(i==2){
					this.getAList()
				}
				
			},
			lianChange(i,item){
				this.idx1 = i;
				this.lian = item;
				this.$refs.qrcode._clearCode();
				if(this.idx==0){
					this.getAds();
					this.getTList();
				}
				if(this.idx==1){
					this.$refs.qrcode._clearCode();
					this.getAds()
					// this.adsInfo = {};
					// this.tAds = '';
				}
				console.log(item,i)
			},
			getBi(){
				let _this = this;
				this.$req('account/show',{id:_this.id},function(res){
					if(res.code==1){
						_this.biDet = res.data;
						_this.lianList = res.data.currency.chain_arr;
						_this.lian = res.data.currency.chain_arr[0];
						_this.getAds()
					}else{
						_this.toast(res.msg)
					}
				})
			},
			goBack(){
				uni.navigateBack({
					delta:1
				})
			}
		}
	}
</script>

<style>
.line_red{
	border-bottom: 2px solid red;
	color: orang;
}
</style>
